package com.lzy.cloud.order.controller;

import com.lzy.cloud.order.dtos.OrderCouponLogDto;
import com.lzy.cloud.order.request.OrderCouponLogRequest;
import com.lzy.cloud.order.response.OrderCouponLogResponse;
import com.lzy.cloud.order.service.OrderCouponLogService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description:订单中券流向记录
 * @author: liyun
 * @create: 2018-07-05 13:49
 */
@RestController
@RequestMapping("/order/coupon/log")
public class OrderCouponLogController {
    @Autowired
    private OrderCouponLogService orderCouponLogService;

    /**
     * 根据订单id查询订单中券流向记录
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/find/by/order/id/{orderId}",method = RequestMethod.GET)
    public Result queryListByOrderId(@PathVariable("orderId") String orderId) {
        Ensure.that(orderId).isNotNull("00010003");
        List<OrderCouponLogDto> list = orderCouponLogService.queryListByOrderId(orderId);
        return new Result(DozerUtils.map(list, OrderCouponLogResponse.class));
    }

    /**
     * 新增订单中券流向记录
     * @param request
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public Result create(@RequestBody OrderCouponLogRequest request) {
        Ensure.that(request).isNotNull("00000002");
        Long id = orderCouponLogService.create(DozerUtils.map(request, OrderCouponLogDto.class));
        Ensure.that(id).isGt(0, "00040001");
        return new Result(id);
    }

    /**
     * 查询订单中券流向记录列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    public Result selectList(@RequestBody OrderCouponLogRequest request){
        Ensure.that(request).isNotNull("00000002");
        List<OrderCouponLogDto> orderCouponLogDtoList = orderCouponLogService.selectList(DozerUtils.map(request,OrderCouponLogDto.class));
        return new Result(DozerUtils.maps(orderCouponLogDtoList,OrderCouponLogResponse.class));
    }

    /**
     * 批量更新订单中券流向记录列表
     * @param request
     * @return
     */
    @RequestMapping(value = "/update/many/log",method = RequestMethod.POST)
    public Result updateManyLog(@RequestBody OrderCouponLogRequest request,String couponIds){
        Ensure.that(request).isNotNull("00000002");
        return new Result(orderCouponLogService.updateManyLog(DozerUtils.map(request,OrderCouponLogDto.class),couponIds));
    }


}
